import { Controller, Get, Post, Body, Patch, Param, Delete, Query, Req, Headers } from '@nestjs/common';
import { ModelService } from './model.service';
import { CreateModelDto } from './dto/create-model.dto';
import { UpdateModelDto } from './dto/update-model.dto';
import { ApiResponse,ApiOperation,ApiBody, ApiParam, ApiQuery } from '@nestjs/swagger';
import { QueryModelDto } from './dto/query-model.dto';
import { CreateUserDto } from '../user/dto/create-user.dto';
import { UserInfoDto } from './dto/user-info.dto';

@Controller('model')
export class ModelController {
  constructor(private readonly modelService: ModelService) {}

  @Post()
  @ApiOperation({summary:'Create a model'})
  @ApiBody({
    type:CreateModelDto,
  })
  @ApiResponse({
    status:200,
    description:'The model has been created successfully',
    type: UpdateModelDto,
  })
  create(@Body() createModelDto: CreateModelDto,@Headers('user') user:UserInfoDto) {
    return this.modelService.create(createModelDto,user && JSON.parse(user as unknown as string));
  }

  @Get()
  @ApiOperation({summary:'Find all model'})
  @ApiQuery({
    name:'name',
    description:'Model name',
    type:'string',
    required:false,
    example:'gpt-3.5-turbo',
  })
  @ApiResponse({
    status:200,
    description:'The model has been created successfully',
    type:[UpdateModelDto],
  })
  findAll(@Query() query:Omit<QueryModelDto,'description'|'content'>,@Headers('user') user:UserInfoDto) {
    return this.modelService.findAll(query,user && JSON.parse(user as unknown as string));
  }

  @Get(':id')
  @ApiOperation({summary:'Find a model'})
  @ApiParam({
    name:'id',
    description:'Model id',
    type:'number',
    required:true,
    example:1,
  })
  @ApiResponse({
    status:200,
    description:'Find a model',
    type: UpdateModelDto,
  })
  findOne(@Param('id') id: string) {
    return this.modelService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'Update a model'})
  @ApiParam({
    name:'id',
    description:'Model id',
    type:'number',
    required:true,
    example:1,
  })
  @ApiResponse({
    status:200,
    description:'Update a model',
    type: UpdateModelDto,
  })
  update(@Param('id') id: string, @Body() updateModelDto: UpdateModelDto) {
    return this.modelService.update(+id, updateModelDto);
  }

  @Delete(':id')
  @ApiOperation({summary:'Delete a model'})
  @ApiParam({
    name:'id',
    description:'Model id',
    type:'number',
    required:true,
    example:1,
  })
  @ApiResponse({
    status:200,
    description:'Delete a model',
    type: UpdateModelDto,
  })
  remove(@Param('id') id: string) {
    return this.modelService.remove(+id);
  }
}
